exir/passes: return PassResult.modified=False when passes leave graph unchanged#19872
Open
vacu9708 wants to merge 1 commit into
Open
exir/passes: return PassResult.modified=False when passes leave graph unchanged#19872vacu9708 wants to merge 1 commit into
vacu9708 wants to merge 1 commit into
Conversation
|
|
… unchanged Several passes in exir/passes/ returned PassResult(graph_module, True) unconditionally, even when they left the graph unchanged. PR pytorch#16231 fixed this for ScalarToTensorPass. This applies the same correction to: - RemoveNoopPass, RemoveToCopyPass, PruneEmptyTensorsPass, ReplaceSymSizeOpPass, RemoveGraphAssertsPass, RemoveNonCoreAtenOpGraphAssertsPass - ToDevicePass — already computed the flag correctly but discarded it RemoveGraphAssertsPass and RemoveNonCoreAtenOpGraphAssertsPass are also refactored to share a helper since they had near-identical loop bodies. Signed-off-by: Youngsik Yang <vacu9708@gmail.com>
Contributor
Author
|
@pytorchbot label "release notes: none" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Several passes in
exir/passes/returnPassResult(graph_module, True)unconditionally — even when they walk the graph and rewrite nothing.A false-positive
modified=Trueforces the consumer to rebuild theExportedProgram(deep-copymodule_call_graph, recompute the graph signature, re-run verifiers) on every pass run, even when nothing changed.PR #16231 fixed this for
ScalarToTensorPass. This PR applies the same pattern to the remaining passes.Passes touched
RemoveNoopPassTrueRemoveToCopyPassTruePruneEmptyTensorsPassTrueRemoveGraphAssertsPassTrue, also calledrecompile()per submodule unconditionallyrecompile()/ DCE on actual mutationRemoveNonCoreAtenOpGraphAssertsPassReplaceSymSizeOpPassTrueToDevicePassmodified, then discarded it and returnedTrueEach fix follows the pattern used by
CSEPass,ScalarToTensorPass, and others: a localmodifiedboolean is set at the point of actual graph mutation and returned viaPassResult(gm, modified). Cleanup operations (eliminate_dead_code,lint,recompile) are only called whenmodified=True.As a minor cleanup,
RemoveGraphAssertsPassandRemoveNonCoreAtenOpGraphAssertsPassare refactored to share a private helper_erase_asserts_from_modules— the two classes were near-identical, differing only in the target op set.flowchart TD A["EdgeProgramManager.transform(MyPass)"] --> B[_transform_with_pass_manager] B --> C{res.modified} C -- True --> D[rebuild ExportedProgram] C -- False --> E[return self\nintended fast path]Test results